#ifndef PROPERTYWIDGET_H
#define PROPERTYWIDGET_H

#include <QWidget>
#include <QListWidgetItem>
#include "../collections/propertycollection.h"

namespace Ui {
    class PropertyWidget;
}

class PropertyWidget : public QWidget
{
    Q_OBJECT

public:
    explicit PropertyWidget(const PropertyCollection& properties_, QWidget *parent = 0);
    ~PropertyWidget();

    void clearPropertyForm();

    QList<KeyPair<GameProperty> > getOrderedProperties();

public slots:
    void addProperty(const GameProperty& property, const QString &key);
    void updateProperty(const QString& oldKey, const GameProperty& newProperty,
                         const QString& newKey);
    void removeProperty(const QString& key);

    void clearAll();

signals:
    void addPropertyRequested(const GameProperty& property, const QString& key);
    void updatePropertyRequested(const QString& oldKey, const GameProperty& newProperty,
                                 const QString& newKey);
    void removePropertyRequested(const QString& key);

protected:
    void changeEvent(QEvent *event);

private slots:
    void on_propList_currentItemChanged(QListWidgetItem* current, QListWidgetItem* previous);
    void on_propAdd_clicked();
    void on_propUpdate_clicked();
    void on_propDelete_clicked();

private:
    Ui::PropertyWidget *ui;

    const PropertyCollection *properties; // (Variable) pointer to const PropertyCollection
    QHash<QString, QListWidgetItem*> keyIndex;
};

#endif // PROPERTYWIDGET_H
